// JavaScript Document
$(function(){
	function upload(){
		alert(1);
		var bar = $('.bar');
		var percent = $('.percent');
		var showimg = $('#showimg');
		var progress = $(".progress");
		var files = $(".files");
		var btn = $(".btn span");
		var options ={    
			dataType:  'json',
			data:$('#myupload').serialize(),
			url:'action.php',
			beforeSend: function() {
				showimg.empty();
				progress.show();
				var percentVal = '0%';
				bar.width(percentVal);
				percent.html(percentVal);
				btn.html("上传中...");
			},
			uploadProgress: function(event, position, total, percentComplete) {
				var percentVal = percentComplete + '%';
				bar.width(percentVal);
				percent.html(percentVal);
			},
			success: function(data) {
				files.html("<b>"+data.name+"("+data.size+"k)</b> <span class='delimg' rel='"+data.pic+"'>删除</span>");
				var img = "http://demo.helloweba.com/upload/files/"+data.pic;
				showimg.html("<img src='"+img+"'>");
				btn.html("添加附件");
			},
			error:function(xhr){
				btn.html("上传失败");
				bar.width('0')
				files.html(xhr.responseText);
			}
		 };		 
		 var form =$("#IbtnEnter");//form1:表单ID  在表单界面只用这一个表单ID
		 $("#Subpic").click(function(){
			  form.ajaxSubmit(options); 
		 });
	}
});